var app =getApp()
var WxParse = require('../../utils/wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
		cardCur: 0,
		swiperList: [],
    limit:5,
    writelist:'',
		searchvalue: '',
		swiper: [
			{
				id: 1,
				photourl: '../../static/banner/banner1.jpg'
			},
			{
				id: 1,
				photourl: '../../static/banner/banner2.jpg'
			}
		],
  },

	searchlist(e) {
		this.setData({
			searchvalue: e.detail.value
		})
	},
	searchdesc() {
		var that = this;
		var value = that.data.searchvalue;
		wx.showLoading({
			title: '搜索中',
		})
		if (value == '') {
			wx.showToast({
				title: '请输入搜索内容',
				duration: 1000,
				icon: 'none'
			})
		} else {
			var setid = app.globalData.cityCode;

			app.core('get', 'xiaochengxu_article_list/limit/5', {
				keywords: value
			}, (res => {
				console.log(res)
				if (res.data.length == 0) {
					wx.showToast({
						title: '暂无相关信息',
						duration: 1000,
						icon: 'none'
					})
				} else {
					wx.navigateTo({
						url: './writesearch?keyword=' + value + '',
					})
				}
				wx.hideLoading()
			}))
		}
	},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) { 

    this.guanggao();
    var limits = this.data.limit
    this.list(5)
  },
	guanggao() {
		var that = this;
		var setid = app.globalData.cityCode;
		wx.showLoading({
			title: '加载中..',
		})
		app.core('get', 'get_advert/site_id/' + setid +'', '', (res) => {
			console.log(res)
			that.setData({
				swiperList: res.data
			})
			wx.hideLoading()
		})
	},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  list(limit){
    var that = this;
    var num = limit +5;
		wx.showLoading({
			title: '加载中..',
		})

    app.core('get','xiaochengxu_article_list/limit/'+limit+'','',(res)=>{
      console.log(res)
      var arr = res.data;
			var htmlAry = [];

      for(var i =0;i<arr.length;i++){
        switch (arr[i].category){
          case 1:
						arr[i].category = '楼盘'
            break;
          case 2:
            arr[i].category = '资讯'
            break;
          case 3:
						arr[i].category = '我的原创 '
            break;
					case 4:
						arr[i].category = '我的日记 '
						break;
					case 5:
						arr[i].category = '热点事件  '
						break;
					case 6:
						arr[i].category = '小道消息 '
						break;
        };

      }
		
      that.setData({
        limit: num,
        writelist:arr
      })
			wx.hideLoading()
    })
  }, // 写一写列表

  getLocalTime(date) {
    // return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/, ' ');
    var date = new Date(date * 1000);//如果date为13位不需要乘1000
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
    var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
    var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
    var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
    return Y + M + D + h + m + s;


  }, // 转换时间戳
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var limit = this.data.limit
    this.list(limit)
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})